home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # static.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: static.frm,v 1.9 1997/06/19 22:26:31 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $conf = "/etc/config/static-route.options";
- $dummy = "/tmp/static.dummy";
- $myname = "static.cgi";
- $title = "Static Routing";
-
- $js_main =
- "type = \"route\";
- $js_account_main
- $js_error_box
- $js_ip
- function testAdd(form) {
- if (!testRoute(form.destination)) return (false);
- return (true);
- }
- function testRoute(Ctrl) {
- if (Ctrl.value == \"\") {
- errorBox (Ctrl, \"To add a new route, first enter \\na \"
- + \"destination IP address.\");
- return (false);
- }
- if (Ctrl.value == \"default\") return (true);
- if (!testIPaddress(Ctrl.value,false)) {
- errorBox (Ctrl, \"The destination address \" + Ctrl.value
- + \"\\nis invalid.\");
- return (false);
- }
- return (true);
- }";
-
- $js_add =
- "$js_standard
- $js_error_box
- $js_ip
- function checkForm(form) {
- if (!testIP(form.route)) return (false);
- return (true);
- }
- function testIP(Ctrl) {
- if (Ctrl.value == \"\") {
- errorBox (Ctrl, \"The IP address of the router \\nis required.\");
- return (false);
- }
- if (!testIPaddress(Ctrl.value,false)) {
- errorBox (Ctrl, \"The router address \" + Ctrl.value
- + \"\\nis invalid.\");
- return (false);
- }
- return (true);
- }";
-
- $js_edit =
- "$js_standard
- $js_error_box
- $js_ip
- function checkForm(form) {
- if (!testIP(form.route)) return (false);
- return (true);
- }
- function testIP(Ctrl) {
- if (Ctrl.value == \"\") {
- errorBox (Ctrl, \"The IP address of the router \\nis required.\");
- return (false);
- }
- if (!testIPaddress(Ctrl.value,false)) {
- errorBox (Ctrl, \"The router address \" + Ctrl.value
- + \"\\nis invalid.\");
- return (false);
- }
- return (true);
- }";
-
- print "Content-type: text/html\n\n";
-
- &get_fields;
- &getGateways;
-
- $delete = 0;
-
- if (%fld) {
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- $fld{'chosen'} =~ /([\w.]+)/;
- $fld{'chosen'} = $1;
- if ($fld{"add"}) {
- &validAdd;
- $val{'metric'} = 1;
- &getAdd;
- exit 0;
- }
- elsif ($fld{"doAdd"}) {
- &valid(0);
- &doAdd;
- $fld{'destination'} = "";
- &getGateways;
- }
- elsif ($fld{"doEdit"}) {
- &valid(1);
- &doEdit;
- &getGateways;
- }
- elsif ($fld{"edit"}) {
- &error(2,"To edit an existing route, first choose one from the list,
- then click the edit button.") if !$fld{'chosen'};
- &getGateways($fld{'chosen'});
- $val{'old_route'} = $rout;
- $val{'old_type'} = $type;
- &putEdit;
- &getEdit;
- exit 0;
- }
- elsif ($fld{"delete"}) {
- &error(2,"To delete an existing route, first choose one from the
- list, then click the delete button.") if !$fld{'chosen'};
- $delete = 1;
- $message = qq|Click "Ok" to save changes.|;
- }
- elsif ($fld{"doit"}) {
- if ($fld{'delGateway'}) { &doDelete; };
- &getGateways;
- }
- else {
- $message = "Use buttons to submit form.";
- }
-
- if (!$message) { $message = "No change made."; }
- %val = %fld;
- }
-
- &generic;
-
- sub valid {
- &error($_[0],"Invalid route address.") if !$fld{'route'} || &check_ipaddr($fld{'route'});
- }
-
- sub validAdd {
- &error(2,"You must provide a route address.") if !$fld{'destination'};
- if ($fld{'destination'} ne "default") {
- &error(2,"Invalid route address.")
- if &check_ipaddr($fld{'destination'});
- }
- }
-
- sub error {
- &error_block($_[1]);
- %val = %fld;
- if ($_[0] == 0) { &getAdd; }
- elsif ($_[0] == 1) { &getEdit; }
- else { &generic; }
- exit 0;
- }
-
- sub doDelete {
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[3] eq $fld{'delGateway'}) {
- $cmd = $_;
- chop $cmd;
- $cmd =~ s/add/delete/;
- $cmd = "/usr/etc" . $cmd;
- system("$cmd > /dev/null 2>&1");
- print OUT "# $_";
- }
- else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- rename($dummy,$conf);
-
- $message .= "Route deleted.";
- }
-
- sub doAdd {
- $cmd = "/usr/etc/route add -$fld{'type'} $fld{'destination'} $fld{'route'}";
- system("$cmd > /dev/null 2>&1");
-
- open(OUT,">> $conf");
- print OUT "$cmd\n";
- close(OUT);
-
- $message = "Route added.";
- }
-
- sub putEdit {
- $val{'type'} = $type;
- $val{'route'} = $rout;
- }
-
- sub doEdit {
- $cmd2 = "/usr/etc/route delete -$fld{'old_type'} $fld{'chosen'} $fld{'old_route'}";
- system("$cmd2 > /dev/null 2>&1");
-
- $cmd1 = "/usr/etc/route add -$fld{'type'} $fld{'chosen'} $fld{'route'}";
- system("$cmd1 > /dev/null 2>&1");
-
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[3] eq $fld{'chosen'}) { print OUT "# $_"; }
- else { print OUT $_; }
- }
- print OUT "$cmd1\n";
- close(IN);
- close(OUT);
- rename($dummy,$conf);
-
- $message .= "Route edited.";
- }
-
- sub getEdit {
- &js_title_block($title,$js_edit);
- &header_block("Edit Route");
-
- print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<input type=hidden name=chosen value=$fld{'chosen'}>\n";
- print "<input type=hidden name=old_route value=$val{'old_route'}>\n";
- print "<input type=hidden name=old_type value=$val{'old_type'}>\n";
-
- print "<center><table width=450>";
-
- print "<tr><th align=left>IP address of route destination:</th><td>
- <tt>$fld{'chosen'}</tt></td></tr>";
- print "<tr><th align=left>IP address of router:</th><td>",
- &text('route',$val{'route'},16),"</td></tr>";
- print "<tr><th align=left>Type of network route:</th><td>",
- &select('type',$val{'type'},'net','host'),"</td></tr>";
-
- print "</table></center>";
-
- print &js_buttons('doEdit','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub getAdd {
- &js_title_block($title,$js_add);
- &header_block("Add New Route");
-
- print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<input type=hidden name=destination value=$fld{'destination'}>";
-
- print "<center><table width=450>";
-
- print "<tr><th align=left>IP address of route destination:</th><td>
- <tt>$fld{'destination'}</tt></td></tr>";
- print "<tr><th align=left>IP address of router:</th><td>",
- &text('route',$val{'route'},16),"</td></tr>";
- print "<tr><th align=left>Type of network route:</th><td>",
- &select('type',$val{'type'},'net','host'),"</td></tr>";
-
- print "</table></center>";
-
- print &js_buttons('doAdd','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub generic {
- &js_title_block($title,$js_main);
- &header_block($title);
-
- print "<i>$message</i>";
-
- print "<form name=AccountForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<center><table width=450>\n";
-
- print "<tr><th align=left>";
- print qq|<input type=submit name=add value="Add New Route" onClick="markAdd()">|;
- print "\n</th><td><input size=19 type=text name=destination
- value=$val{'destination'}>";
- print "</td></tr>\n";
-
- if ($delete) {
- undef @locList;
- foreach $arg (@routes) {
- if ($arg ne $fld{'chosen'}) {
- push(@locList,$arg); }
- }
- print "<input type=hidden name=delGateway value=$fld{'chosen'}>";
- } else { @locList = @routes; }
-
- print "<tr><th align=left>";
- print qq|<input type=submit name=edit value="Edit Selected Route" onClick="markEdit()">|;
- print "\n</th><td rowspan=2>", &choice_list(*locList,"chosen",20), "</td></tr>\n";
-
- print "<tr><th align=left>";
- print qq|<input type=submit name=delete value="Delete Selected Route" onClick="markDelete()">|;
- print "</th></tr>\n";
- print "\n</table></center>\n";
-
- print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub getGateways {
- undef @routes;
-
- open(GATE, "< $conf");
- while (<GATE>) {
- @items = split(/\s+/);
- if ($items[0] ne 'route' && $items[1] ne 'add') { next; }
- push(@routes,$items[3]);
- if ($items[3] eq $_[0]) {
- $type = substr($items[2],1);
- $rout = $items[4];
- }
- }
- close(GATE);
- }
-